/**
 * 
 */
package server.game;

import server.exception.ServerException;

/**
 * Defines causes of leaving the table.
 * 
 * @author Kamil Nowak
 *
 */
public enum LeavetableCause {
	
	/**
	 * Opponent left before begining of a game.
	 */
	OPPONENT_LEFT,
	/**
	 * Opponent left after begining of a game
	 */
	OPPONENT_LEFT_DURING_GAME;

	
	/**
	 * Defines LeavetableCause label - Integer mapping
	 * @param c value to map
	 * @return corresponding Integer value or 0 if mapping does not exist
	 */
	public static Integer getCode(LeavetableCause c) {
		switch (c) {
			case OPPONENT_LEFT: return 1;
			case OPPONENT_LEFT_DURING_GAME: return 2;
		}
		return 0;
	}
	
	/**
	 * Defines Integer - LeavetableCause label mapping
	 * @param c value to map
	 * @return corresponding value
	 * @throws ServerException mapping does not exist
	 */
	public static LeavetableCause getCause(int c) throws ServerException {
		switch (c) {
			case 1: return OPPONENT_LEFT;
			case 2: return OPPONENT_LEFT_DURING_GAME;

			default: throw new ServerException("No such cause");
		}
		
	}
}
